﻿using System;
using System.Collections.Specialized;
using PostSharp.Aspects;
using PostSharp.Aspects.Dependencies;
using SmartReactives.List;

namespace SmartReactives.PostSharp.NotifyPropertyChanged
{
    /// <summary>
    /// Makes a list property reactive.
    /// </summary>
    [Serializable]
    [AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "SmartNotifyPropertyChanged")]
    public class ReactiveListAttribute : LocationInterceptionAspect
    {
        /// <inheritdoc />
        public sealed override void OnGetValue(LocationInterceptionArgs args)
        {
            ReactiveManagerWithList.Evaluate(() =>
            {
                base.OnGetValue(args);
                return (INotifyCollectionChanged) args.GetCurrentValue();
            });
        }
    }
}